//
//  HEDocImMsgModel.m
//  HealthElderly
//
//  Created by 吴欧 on 2020/12/23.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEDocImMsgModel.h"
#import "HEIMPrivateDoctorObject.h"

@implementation HEDocImMsgModel

- (NSString *)KTitleName {
    if (!_KTitleName) {
        if ([@"im" isEqualToString:_message_type]) {
            if ([@"0" isEqualToString:_msgType]) {
                // 私人医生
                _KTitleName = [NSString stringWithFormat:@"%@ | %@", _realname, _post_name];
            }else if([@"1" isEqualToString:_msgType]) {
                // 团队服务
                _KTitleName = _teamName;
            }else if([@"4" isEqualToString:_msgType]) {
                // 群聊
                _KTitleName = _group_name;
            }
        }else{
            // 图文
            _KTitleName = [NSString stringWithFormat:@"%@ | %@", _realname, _post_name];
        }
        
    }
    return _KTitleName;
}

- (NSString *)Kcreate_date {
    if (!_Kcreate_date) {
        _Kcreate_date = [NSDate inputTimeStr:[NSDate timestampToDate:_create_date formaterMode:NSDateFormaterModeDefault]];
    }
    return _Kcreate_date;
}

- (NSString *)KHospAndDept {
    if (!_KHospAndDept) {
        if ([@"im" isEqualToString:_message_type]) {
            if ([@"0" isEqualToString:_msgType]) {
                // 私人医生
                _KHospAndDept = [NSString stringWithFormat:@"%@  %@", _hospital_name, _depart_name];
            }else if([@"1" isEqualToString:_msgType]) {
                // 团队服务
                _KHospAndDept = [NSString stringWithFormat:@"%@  %@", _teamHospitalName, _teamDeptName];
            }else {
                _KHospAndDept = @"-";
            }
        }else{
            // 图文
            _KHospAndDept = [NSString stringWithFormat:@"%@  %@", _hospital_name, _depart_name];
        }
    }
    return _KHospAndDept;
}

- (UIColor *)KTagColor {
    if (!_KTagColor) {
        if ([@"im" isEqualToString:_message_type]) {
            if ([@"0" isEqualToString:_msgType]) {
                _KTagColor = COrangeColor;
            }else if([@"1" isEqualToString:_msgType]) {
                _KTagColor = KHexColor(@"39B449");
            }else if([@"3" isEqualToString:_msgType]) {
                _KTagColor = CPriceColor;
            }else if([@"4" isEqualToString:_msgType]) {
                _KTagColor = CPriceColor;
            }
        }else {
            _KTagColor = CNavBgColor;
        }
    }
    return _KTagColor;
}

- (NSString *)KTag {
    if (!_KTag) {
        if ([@"im" isEqualToString:_message_type]) {
            if ([@"0" isEqualToString:_msgType]) {
                // 私人医生
                _KTag = @"私人";
            }else if([@"1" isEqualToString:_msgType]) {
                // 团队服务
                _KTag = @"团队";
            }else if([@"3" isEqualToString:_msgType]) {
                // 居家医养
                _KTag = @"病床";
            }else if([@"4" isEqualToString:_msgType]) {
                // 居家医养
                _KTag = @"群聊";
            }
        }else {
            _KTag = @"图文";
        }
    }
    return _KTag;
}

- (NSString *)Kmsg {
    if (!_Kmsg) {
        if ([@"im" isEqualToString:_message_type]) {
            NSString *cntStr = @"";
            if (self.contentModel.type == HEIMMessageTypeImage) {
                cntStr = @"[图片]";
            }else if (self.contentModel.type == HEIMMessageTypeAudio) {
                cntStr = @"[语音]";
            }else if (self.contentModel.type == HEIMMessageTypeConsulReport) {
                cntStr = @"[咨询报告]";
            }else if (self.contentModel.type == HEIMMessageTypeProduct) {
                cntStr = [NSString stringWithFormat:@"[服务推荐-%@]", _contentModel.product_name];
            }else if (self.contentModel.type == HEIMMessageTypeGroupNotif) {
                cntStr = [NSString stringWithFormat:@"%@ %@", @"[群公告]", self.contentModel.content];
            }else if ([DYTools isBlankString: _content]) { // 私人签约消息
                HEIMPrivateDoctorObject *private = [HEIMPrivateDoctorObject mj_objectWithKeyValues: _extras];
                cntStr = private.disease_desc;
            }else {
                cntStr = self.contentModel.content;
            }
            
            if (self.contentModel.actor == HEActorTypeUser || [DYTools isBlankString: _content]) {
                cntStr = [NSString stringWithFormat:@"我：%@", cntStr];
            }else {
                cntStr = [DYTools isBlankString:_contentModel.nickname] ? cntStr : [NSString stringWithFormat:@"%@：%@", _contentModel.nickname, cntStr];
            }
            _Kmsg = cntStr;
        }else { // tw
            NSString *cntStr = @"";

            if ([TWIM_TEXT isEqualToString: self.twContentModel.type]) {
                cntStr = self.twContentModel.content;
            }
            else if ([TWIM_IMAGE isEqualToString: self.twContentModel.type]) {
                cntStr = @"[图片]";
            }
            else if ([TWIM_VIDEO isEqualToString: self.twContentModel.type]) {
                cntStr = @"[视频]";
            }
            else if ([TWIM_AUDIO isEqualToString: self.twContentModel.type]) {
                cntStr = @"[语音]";
            }
            
            if (self.isMe) {
                if (self.twContentModel == NULL) { // 图文表单消息
                    cntStr = [NSString stringWithFormat:@"我：%@", self.formContents.firstObject.content];
                }else{
                    cntStr = [NSString stringWithFormat:@"我：%@", cntStr];
                }
            }else {
                cntStr = [NSString stringWithFormat:@"%@：%@", _realname, cntStr];
            }
            _Kmsg = cntStr;
        }
    }
    return _Kmsg;
}

- (NSString *)KAvatar {
    if (!_KAvatar) {
        if ([@"im" isEqualToString:_message_type]) {
            if ([@"0" isEqualToString:_msgType]) {
                _KAvatar = _avatar;
            }else if([@"1" isEqualToString:_msgType]) {
                // 团队服务
                _KAvatar = _teamIcon;
            }
        }else {
            _KAvatar = _avatar;
        }
    }
    return _KAvatar;
}

- (BOOL)isMe {
    if ([DYTools isBlankString:_user_ask]) {
        _isMe = NO;
    }else {
        _isMe = YES;
    }
    return _isMe;
}

- (BOOL)KIsRead {
    if (self.isTW) {
        _KIsRead = _is_read;
    }else {
        if ([[UserManager sharedUserManager].curUserInfo.id isEqualToString:_from_id]) {
            _KIsRead = YES;
        }else {
            _KIsRead = _is_read;
        }
    }
    return _KIsRead;
}

- (HETWIMInfoModel *)twContentModel {
    if (!_twContentModel) {
        if (self.isMe) {
            NSObject *dict = [DYTools getContainersObjectFromJsonString: _user_ask];
            if ([dict isKindOfClass:NSArray.class]) {
                _formContents = [HETWIMInfoModel mj_objectArrayWithKeyValuesArray:dict];
            }else {
                _twContentModel = [HETWIMInfoModel mj_objectWithKeyValues:dict];
            }
            
        }else {
            NSDictionary *dict = [DYTools getContainersObjectFromJsonString: _doc_response];
            _twContentModel = [HETWIMInfoModel mj_objectWithKeyValues:dict];
        }
    }
    return _twContentModel;
}

- (HEIMInfoContentEntity *)contentModel {
    if (!_contentModel) {
        NSDictionary *dict = [DYTools getContainersObjectFromJsonString: _content];
        _contentModel = [HEIMInfoContentEntity mj_objectWithKeyValues:dict];
    }
    return _contentModel;
}

// 黑名单
//+ (NSArray *)mj_ignoredPropertyNames {
//    return @[@"contentModel", @"formContents", @"twContentModel"
//             , @"KTagColor" , @"Kmsg", @"KTag"];
//}

- (BOOL)isTW {
    if([@"ask" isEqualToString:_message_type]) {
        _isTW = YES;
    }
    return _isTW;
}

- (BOOL)privateExpire {
    _privateExpire = _user_doc_flag == 1 ? NO : YES;
    return _privateExpire;
}

@end
